#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
智能文本审核系统配置文件
纯本地分析配置，无需外部API
"""

import os
from dotenv import load_dotenv

# 加载环境变量
load_dotenv()

class Config:
    """基础配置"""
    SECRET_KEY = os.environ.get('SECRET_KEY') or 'dev-secret-key-change-in-production'
    
    # Flask配置
    MAX_CONTENT_LENGTH = int(os.environ.get('MAX_CONTENT_LENGTH', 16 * 1024 * 1024))  # 16MB
    UPLOAD_FOLDER = 'uploads'
    RESULTS_FOLDER = 'results'
    ALLOWED_EXTENSIONS = {'txt', 'csv', 'json', 'log'}
    
    # 审核配置
    DEFAULT_MODERATION_MODE = 'local'  # 强制本地模式
    ENABLE_BATCH_PROCESSING = os.environ.get('ENABLE_BATCH_PROCESSING', 'true').lower() == 'true'
    MAX_BATCH_SIZE = int(os.environ.get('MAX_BATCH_SIZE', 1000))
    
    # 本地模型配置
    LOCAL_MODELS = {
        'sentiment': {
            'name': 'uer/roberta-base-finetuned-jd-binary-chinese',
            'enabled': True,
            'max_length': 512
        },
        'toxicity': {
            'name': 'IDEA-CCNL/Erlangshen-MacBERT-110M-Sentiment-Chinese',
            'enabled': True,
            'max_length': 512
        }
    }
    
    # 敏感词配置
    SENSITIVE_WORDS_FILE = 'sensitive_words.json'
    ENABLE_KEYWORD_FILTER = True
    ENABLE_SENTIMENT_ANALYSIS = True
    ENABLE_TOXICITY_DETECTION = True
    
    # 风险评分配置
    RISK_THRESHOLDS = {
        'low': 30,
        'medium': 60,
        'high': 80
    }
    
    # 评分权重配置
    RISK_WEIGHTS = {
        'keyword_match': 0.4,
        'sentiment_analysis': 0.3,
        'toxicity_detection': 0.3
    }
    
    # 日志配置
    LOG_LEVEL = os.environ.get('LOG_LEVEL', 'INFO')
    LOG_FILE = 'text_moderation.log'
    LOG_MAX_SIZE = 10 * 1024 * 1024  # 10MB
    LOG_BACKUP_COUNT = 5
    
    # 性能配置
    MAX_WORKERS = int(os.environ.get('MAX_WORKERS', 4))
    REQUEST_TIMEOUT = int(os.environ.get('REQUEST_TIMEOUT', 30))
    
    # 缓存配置
    ENABLE_CACHE = os.environ.get('ENABLE_CACHE', 'true').lower() == 'true'
    CACHE_SIZE = int(os.environ.get('CACHE_SIZE', 1000))
    CACHE_TTL = int(os.environ.get('CACHE_TTL', 3600))  # 1小时
    
    # 用户界面配置
    MAX_DISPLAY_TEXT_LENGTH = 200
    SHOW_DETAILED_RESULTS = True
    ENABLE_HISTORY = True
    MAX_HISTORY_ITEMS = 50
    
    # 文件处理配置
    ENCODING = 'utf-8'
    CHUNK_SIZE = 1024 * 1024  # 1MB
    SUPPORTED_DELIMITERS = [',', '\t', '|', ';']
    
    # 安全配置
    ENABLE_RATE_LIMIT = False  # 开发环境禁用
    RATE_LIMIT_REQUESTS = 100
    RATE_LIMIT_WINDOW = 3600  # 1小时
    
    # 调试配置
    DEBUG = os.environ.get('DEBUG', 'false').lower() == 'true'
    TESTING = os.environ.get('TESTING', 'false').lower() == 'true'